package cn.doitedu.profile.utils;

import cn.doitedu.eagle.beans.LogBean;
import cn.doitedu.demo.LogBeanFlat;
import com.alibaba.fastjson.JSON;

import java.util.HashMap;

/***
 * @author hunter.d
 * @qq 657270652
 * @wx haitao-duan
 * @date 2021/3/13
 **/
public class LogBeanUtil {

    public static LogBeanFlat flatBean(LogBean bean) throws Exception {


        LogBeanFlat flatBean = new LogBeanFlat();

        flatBean.setAccount(bean.getAccount()==null?"":bean.getAccount());
        flatBean.setAppId(bean.getAppId()==null?"":bean.getAppId());
        flatBean.setAppVersion(bean.getAppVersion()==null?"":bean.getAppVersion());
        flatBean.setCarrier(bean.getCarrier()==null?"":bean.getCarrier());
        flatBean.setDeviceId(bean.getDeviceId()==null?"":bean.getDeviceId());
        flatBean.setDeviceType(bean.getDeviceType()==null?"":bean.getDeviceType());
        flatBean.setEventId(bean.getEventId()==null?"":bean.getEventId());
        flatBean.setIp(bean.getIp()==null?"":bean.getIp());
        flatBean.setLatitude(bean.getLatitude()+"");
        flatBean.setLongitude(bean.getLongitude()+"");
        flatBean.setNetType(bean.getNetType());
        flatBean.setOsName(bean.getOsName());
        flatBean.setOsVersion(bean.getOsVersion());
        flatBean.setReleaseChannel(bean.getReleaseChannel());
        flatBean.setResolution(bean.getResolution());
        flatBean.setSessionId(bean.getSessionId());
        flatBean.setTimeStamp(bean.getTimeStamp()+"");

        HashMap<String, String> props = bean.getProperties();
        flatBean.setAccount(props.get("account"));
        flatBean.setAdCampain(props.get("adCampain"));
        flatBean.setAdId(props.get("adId"));
        flatBean.setAdLocation(props.get("adLocation"));
        flatBean.setCouponId(props.get("couponId"));
        flatBean.setKeywords(props.get("keywords"));
        flatBean.setPageId(props.get("pageId"));
        flatBean.setProductId(props.get("productId"));
        flatBean.setProductNumb(props.get("productNumb"));
        flatBean.setRefType(props.get("refType"));
        flatBean.setRefUrl(props.get("refUrl"));
        flatBean.setShareMethod(props.get("shareMethod"));
        flatBean.setTitle(props.get("title"));
        flatBean.setUrl(props.get("url"));
        flatBean.setUtm_campain(props.get("utm_campain"));
        flatBean.setUtm_loctype(props.get("utm_loctype"));
        flatBean.setUtm_source(props.get("utm_source"));

        return flatBean;

    }

    public static void main(String[] args) throws Exception {
        String json = "{\"account\":\"ufM1CsM\",\"appId\":\"cn.doitedu.app1\",\"appVersion\":\"3.4\",\"carrier\":\"小米移动\",\"deviceId\":\"GXhqCWJcxnK5\",\"deviceType\":\"IPHONE-8PLUS\",\"eventId\":\"adShow\",\"ip\":\"33.147.41.181\",\"latitude\":21.887531857739106,\"longitude\":108.11579720910733,\"netType\":\"5G\",\"osName\":\"ios\",\"osVersion\":\"8.8\",\"properties\":{\"adCampain\":\"12\",\"adId\":\"12\",\"adLocation\":\"10\",\"pageId\":\"85\"},\"releaseChannel\":\"TapTap\",\"resolution\":\"1024*768\",\"sessionId\":\"vZANshdQA70\",\"timeStamp\":1615390077380}";


        LogBean logBean = JSON.parseObject(json, LogBean.class);
        LogBeanFlat flatBean = flatBean(logBean);

        System.out.println(flatBean);


    }

}
